package rss_POJO;

import java.util.Date;
import java.util.Collection;
import java.io.Serializable;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.UniqueConstraint;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author RS-team
 */
@Entity
@Table(name = "MUSICGROUP")
//@Table(name = "MUSICGROUP", uniqueConstraints = {
//    @UniqueConstraint(columnNames = {"NAME"})})
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "MusicGroup.findAll", query = "SELECT m FROM MusicGroup m"),
    @NamedQuery(name = "MusicGroup.findByMusicgroupid", query = "SELECT m FROM MusicGroup m WHERE m.musicgroupid = :musicgroupid"),
    @NamedQuery(name = "MusicGroup.findByName", query = "SELECT m FROM MusicGroup m WHERE m.name = :name"),
    @NamedQuery(name = "MusicGroup.findByFormationdate", query = "SELECT m FROM MusicGroup m WHERE m.formationdate = :formationdate")})
public class MusicGroup implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "MUSICGROUPID")  // είναι not nullable αλλά και unique ως primary key
        @Basic(optional = false)
        private Integer musicgroupid;
    @Column(name = "NAME", nullable = false, unique = true, length = 100)  // μοναδικότητα κύριου αναγνωριστικού πεδίου αναζήτησης
        @Basic(optional = false)
        private String name;
    @Column(name = "FORMATIONDATE", nullable = true, unique = false)
        @Basic(optional = true)
        @Temporal(TemporalType.DATE)
        private Date formationdate;
    
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "musicgroupId")
        private Collection<Album> albumCollection;
    @ManyToMany
        @JoinTable(name = "MUSICGROUP_ARTIST", joinColumns = {
            @JoinColumn(name = "MUSICGROUP_ID", referencedColumnName = "MUSICGROUPID")}, inverseJoinColumns = {
            @JoinColumn(name = "ARTIST_ID", referencedColumnName = "ARTISTID")})
        private Collection<Artist> artistCollection;

     /* default constructor */
    public MusicGroup() {
    }
    /* "τεμπέλικος" constructor χωρίς τα nullable πεδία */
    public MusicGroup(String name) {
        this.musicgroupid = null;  // ετσι κι αλλιώς θα το ορίσει η ΒΔ
        this.name = name;
    }
    /* και ο πλήρης constructor */
    public MusicGroup(String name, Date formationdate) {
        this.musicgroupid = null;  // ετσι κι αλλιώς θα το ορίσει η ΒΔ
        this.name = name;
        this.formationdate = formationdate;
    }

    /* getters */
    public Integer getMusicgroupid() { return musicgroupid; }
    public String getName() { return name; }
    public Date getFormationdate() { return formationdate; }

    /* setters εκτός ίσως από το primary key */
    public void setMusicgroupid(Integer musicgroupid) { this.musicgroupid = musicgroupid; }
    public void setName(String name) { this.name = name; }
    public void setFormationdate(Date formationdate) { this.formationdate = formationdate; }

    @XmlTransient
    /* getter και setter για την artistCollection */
    public Collection<Artist> getArtistCollection() {
        return artistCollection;
    }
    public void setArtistCollection(Collection<Artist> artistCollection) {
        this.artistCollection = artistCollection;
    }

    @XmlTransient
    /* getter και setter για την albumCollection */
    public Collection<Album> getAlbumCollection() {
        return albumCollection;
    }
    public void setAlbumCollection(Collection<Album> albumCollection) {
        this.albumCollection = albumCollection;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (musicgroupid != null ? musicgroupid.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof MusicGroup)) {
            return false;
        }
        MusicGroup other = (MusicGroup) object;
        if ((this.musicgroupid == null && other.musicgroupid != null) || (this.musicgroupid != null && !this.musicgroupid.equals(other.musicgroupid))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "rss_POJO.MusicGroup[ musicgroupid=" + musicgroupid + " ]";
    }
    
}